package tech.lq0.dreamaticvoyage.gui.screen;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import tech.lq0.dreamaticvoyage.Utils;
import tech.lq0.dreamaticvoyage.block.entity.CrystalCutterBlockEntity;
import tech.lq0.dreamaticvoyage.gui.menu.CrystalCutterMenu;

@OnlyIn(Dist.CLIENT)
public class CrystalCutterScreen extends AbstractContainerScreen<CrystalCutterMenu> {

    private static final ResourceLocation TEXTURE = Utils.loc("textures/gui/crystal_cutter.png");

    public CrystalCutterScreen(CrystalCutterMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
        super(pMenu, pPlayerInventory, pTitle);
        imageWidth = 176;
        imageHeight = 166;
    }

    @Override
    protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) {
        int i = (this.width - this.imageWidth) / 2;
        int j = (this.height - this.imageHeight) / 2;
        pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight);

        int energy = this.menu.getEnergy();
        pGuiGraphics.blit(TEXTURE, i + 75, j + 62, 177, 17, (int) (21f * energy / 4f), 4, 256, 256);

        int progress = this.menu.getOutputProgress();
        pGuiGraphics.blit(TEXTURE, i + 75, j + 40, 177, 0,
                (int) (22f * progress / (float) CrystalCutterBlockEntity.PROCESS_TIME), 16, 256, 256);
    }

    @Override
    public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
        this.renderBackground(pGuiGraphics);
        super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
        this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
    }

    @Override
    protected void init() {
        super.init();
        this.titleLabelX = 8;
        this.titleLabelY = 5;
        this.inventoryLabelX = 8;
        this.inventoryLabelY = 74;
    }
}
